package com.example.zhyq.visit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.example.base.entity.VisitBeanItem
import com.example.base.mvvm.BaseActivity
import com.example.zhyq.R
import com.example.zhyq.databinding.ActivityVisitAddBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/VisitAddActivity")
class VisitAddActivity : BaseActivity<ActivityVisitAddBinding,VisitViewModel>() {


    override fun initView() {
        binding.headVisitAdd.apply {
            headerBack.setOnClickListener {
                finish()
            }
            headerTitle.text = "添加访客"
            headerAdd.setOnClickListener {
                val visitBeanItem = VisitBeanItem()
//                val appointmentTime: String = "",
//                val approved: Boolean = false,
//                val attachments: List<String> = emptyList(),
//                val employeeId: Int = 0,
//                val id: Int = 0,
//                val idNumber: String = "",
//                val phoneNumber: String = "",
//                val plateNumber: String = "",
//                val purpose: String = "",
//                val requestParking: Boolean = false,
//                val visitStatus: String = "",
//                val visitorName: String = ""
                visitBeanItem.appointmentTime = binding.visitaddDate.text.toString() +" "+binding.visitaddStart.text.toString()
                visitBeanItem.employeeId = 1
                visitBeanItem.idNumber = binding.visitaddCard.text.toString()
                visitBeanItem.phoneNumber = binding.visitaddPhone.text.toString()
                visitBeanItem.plateNumber = binding.visitaddCarNo.text.toString()
                visitBeanItem.purpose = binding.visitaddPurpose.text.toString()
                visitBeanItem.requestParking = binding.visitaddSwitch.isChecked
                visitBeanItem.visitorName = binding.visitaddUser.text.toString()
                vm.addVisit(visitBeanItem)
            }
        }

        binding.visitaddIvdate.setOnClickListener {
            showDateDialog(binding.visitaddDate)
        }

        binding.visitaddIvstart.setOnClickListener {
            showTimeDialog(binding.visitaddStart)
        }

        binding.visitaddIvend.setOnClickListener {
            showTimeDialog(binding.visitaddEnd)
        }

        binding.visitaddSwitch.setOnCheckedChangeListener { compoundButton, b ->
            binding.visitaddCarNo.isEnabled = b
        }
    }

    override fun initData() {
        vm.addVisit.observe(this) {
            ToastUtils.showLong("添加成功")
            finish()
        }
    }
}